package com.h2psoft.truyen.tranh.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.h2psoft.truyen.tranh.R;
import com.h2psoft.truyen.tranh.objects.ObjChaper;

public class AdapterListChap extends BaseAdapter {
	private final Context context;
	private ArrayList<ObjChaper> arrChapers;
	private LayoutInflater inflater;
	private ViewHolder viewHolder;

	public AdapterListChap(Context context, ArrayList<ObjChaper> arrChapers) {
		this.context = context;
		this.arrChapers = arrChapers;
		initView();
	}

	private void initView() {
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.adapter_list_chap, parent, false);
			viewHolder = new ViewHolder();
			viewHolder.tvwChapName = (TextView) convertView.findViewById(R.id.tvwChapName);
			convertView.setTag(viewHolder);
		} else
			viewHolder = (ViewHolder) convertView.getTag();
		ObjChaper objChaper = arrChapers.get(position);
		viewHolder.tvwChapName.setText(objChaper.getContent());
		return convertView;
	}

	class ViewHolder {
		TextView tvwChapName;
	}

	@Override
	public int getCount() {
		return arrChapers.size();
	}

	@Override
	public Object getItem(int arg0) {
		return arrChapers.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}
}